import math
from coin.exchange.uniswap_base.constants import ADDR_TO_DECIMAL_MULTIPLIER


class UniswapNumber:
    def __init__(self, contract_address: str, value: float = 0.0):
        self.contract_address = contract_address
        self.value = value

    def __int__(self) -> int:
        return int(self.value)

    def __float__(self) -> float:
        return self.value

    def _eth_get(self) -> int:
        return int(self.value / ADDR_TO_DECIMAL_MULTIPLIER[self.contract_address])

    def _eth_set(self, eth_value: float) -> None:
        self.value = eth_value * ADDR_TO_DECIMAL_MULTIPLIER[self.contract_address]

    def __eq__(self, other: "UniswapNumber") -> bool:
        return math.isclose(self.value, other.value)

    def __lt__(self, other: "UniswapNumber") -> bool:
        return (self != other) and (self.value < other.value)

    def __gt__(self, other: "UniswapNumber") -> bool:
        return (self != other) and (self.value > other.value)

    eth = property(fget=_eth_get, fset=_eth_set, fdel=None, doc=None)
